//
//  HNNewsDetailCell.m
//  HappyNews
//
//  Created by Sai on 15/12/28.
//  Copyright © 2015年 bai wang. All rights reserved.
//

#import "HNNewsDetailCell.h"
#import <UIImageView+WebCache.h>
@implementation HNNewsDetailCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self addSubview];
    }
    return self;
}

- (void)addSubview
{
    _NewsDatailCellImageView = [[UIImageView alloc]initWithFrame:CGRectMake(kScreenWidth / 4 * 2.8, 10, kScreenWidth / 4, 100 - 15)];
    
    [self.contentView addSubview:_NewsDatailCellImageView];
    
    _NewsDatailCellLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 5, kScreenWidth / 3 * 2, 100 / 3 * 2)];
    _NewsDatailCellLabel.numberOfLines = -1;
    
    [self.contentView addSubview:_NewsDatailCellLabel];
    
}


- (void)setModel:(HNNewsDetailStories *)model
{
    _model = model;
    // 判断里面是否有图片
    if (_model.images != nil) {
        // 说明有图片
        [self addSubview];
        [_NewsDatailCellImageView sd_setImageWithURL:[NSURL URLWithString:model.images[0]] placeholderImage:nil];
        _NewsDatailCellLabel.text = model.title;
    }else{
        // 说明没有图片 那么就重新布局label位置
        _NewsDatailCellImageView.frame = CGRectMake(0, 0, 0, 0);
        _NewsDatailCellLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 5, kScreenWidth - 20, 100 / 3 * 2)];
        _NewsDatailCellLabel.text = model.title;
        _NewsDatailCellLabel.numberOfLines = -1;
        [self.contentView addSubview:_NewsDatailCellLabel];
    }
    
}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
